package com.example.login;

import androidx.appcompat.app.AppCompatActivity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class RegisterActivity extends AppCompatActivity {
    private EditText et_username,et_pwd;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        et_username=findViewById(R.id.et_username);
        et_pwd=findViewById(R.id.et_pwd);
        findViewById(R.id.toolbar).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               finish();
            }
        });
        findViewById(R.id.register).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               String username= et_username.getText().toString();
               String password= et_pwd.getText().toString();
               if(TextUtils.isEmpty(username)||TextUtils.isEmpty(password)){
                   Toast.makeText(RegisterActivity.this, "请填写完整信息", Toast.LENGTH_SHORT).show();
               }else{
                   int row=UserDbHelper.getInstance(RegisterActivity.this).register(username,password,"暂无~~~");
                  if(row>0){
                      Toast.makeText(RegisterActivity.this, "注册成功,请登录", Toast.LENGTH_SHORT).show();
                      finish();
                  }


               }


            }
        });
    }
}